import 'package:flutter/material.dart';

// 一个默认宽度为40的下拉选择框,或者
class SelectList extends AnimatedWidget {
  const SelectList({
    Key key, 
    Animation<double> animation, 
    this.lists, 
    this.tapCb, 
    this.height,
    this.width
  }): 
  super(key: key, listenable: animation);
  
  final List<String> lists;
  final Function tapCb;
  final double height;
  final double width;
  @override
  Widget build(BuildContext context) {
    final Animation<double> animation = listenable;
    return Positioned(
      height: height * lists.length / 10 * animation.value,
      width: width,
      left: 0,
      top: 40,
      child: ListView(
        children: List<Widget>.generate(lists.length, (int i) => _ListItem(text: lists[i], tapCb: tapCb))
      ),
    );
  }
}


class _ListItem extends StatelessWidget {
  const _ListItem({ Key key, this.tapCb, this.text }):super(key: key);
  final Function tapCb;
  final String text;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap:  () => tapCb(text),
      child: Container(
        color: const Color(0xFFFFF000),
        child: Text(text),
      ),
    );
  }
}